﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ChemicalEquilibrium
{
    /// <summary>
    /// 反应物
    /// </summary>
    public class Reactant
    {
        public bool Activated = false;
        public bool Combined { get { return this.Reactants.Count > 0; } }

        protected Queue<Reactant> Reactants = new Queue<Reactant>();

        /// <summary>
        /// 构造反应
        /// </summary>
        /// <param name="reactants">化合物</param>
        public Reactant(params Reactant[] reactants)
        {
            this.Combine(reactants);
        }

        /// <summary>
        /// 化合反应
        /// </summary>
        /// <param name="reactants">化合物</param>
        public void Combine(params Reactant[] reactants)
        {
            foreach (Reactant R in reactants)
            {
                this.Reactants.Enqueue(R);
            }
        }

        /// <summary>
        /// 分解反应
        /// </summary>
        /// <returns>分解物</returns>
        public Reactant Resolve()
        {
            if (this.Reactants.Count > 0)
                return Reactants.Dequeue();
            else
                return null;
        }

        public static void BuildReactant(int count, params Queue<Reactant>[] reactants)
        {
            for (int i = 0; i < reactants.Length; i++)
            {
                if (reactants[i] == null) reactants[i] = new Queue<Reactant>();

                for (int j = 0; j < count; j++)
                {
                    reactants[i].Enqueue(new Reactant());
                }
            }
        }

        public static void BuildReactantCombined(int count, params Queue<Reactant>[] reactants)
        {
            for (int i = 0; i < reactants.Length; i++)
            {
                if (reactants[i] == null) reactants[i] = new Queue<Reactant>();

                for (int j = 0; j < count; j++)
                {
                    reactants[i].Enqueue(new Reactant(new Reactant(), new Reactant()));
                }
            }
        }

    }
}
